﻿; if (window.jQuery) {

    _$$ = window.$$;

    window.jQueryCache = window.$$ = function($) {

        $.extend({
            object_cache: {}
        });

        $.fn.extend({

            cache: function(key) {
                if (typeof key == "string") {
                    return $.object_cache[key] = this;
                }
            }

        });

        var jQueryCache = function(key, reload) {
            if (!key || typeof key != "string") {
                return false;
            }

            if (reload || !$.object_cache[key]) {
                $(key).cache(key);
            }

            return $.object_cache[key];
        };

        jQueryCache.remove = function(key) {
            $.object_cache[key] = null;
        };

        jQueryCache.clear = function() {
            $.object_cache = [];
        };

        jQueryCache.noConflict = function() {
            window.$$ = _$$;
            return jQueryCache;
        };

        return jQueryCache;

    } (jQuery);

}
var JyAjax = {
    MsgBox:"#MsgBox",
    ShowLoading:function(){
        $.moonbox.loading(); 
    },
    HideLoading:function(){
        $.moonbox.close();
    },
    Error:function(){
        $.moonbox.error();
    },
    GetHtml:function(id,url){
        $.ajax({
	        url: url,
	        beforeSend: function(XMLHttpRequest){
		        JyAjax.ShowLoading();
	        },
	        success: function(data, textStatus){
		        $("#"+id).html(data);
	        },
	        complete: function(XMLHttpRequest, textStatus){
		        JyAjax.HideLoading();
	        },
	        error: function(){
		        JyAjax.Error();
	        }
        })
    },
    GetXml:function(id,url,fnode,node,html){
        $.ajax({
	        url: url,
	        beforeSend: function(XMLHttpRequest){
		        JyAjax.ShowLoading();
	        },
	        success: function(data, textStatus){
	            $("#"+id).html("");
	            $(fnode,data).each(function(i, domEle){
			        $("#"+id).append(html.replace("$node",$(domEle).children(node).text()));
		        });
	        },
	        complete: function(XMLHttpRequest, textStatus){
		        JyAjax.HideLoading();
	        },
	        error: function(){
		        JyAjax.Error();
	        }
        })
    }
}
function PostAjax(href,cData){
    //alert(cData);
    $.ajax({
        url:href,
        data:cData,
        type:'post',
        success:function(data){
            $.moonbox.ok('操作成功！');
        },
        error:function(){$.moonbox.error('操作失败！');}
    });
}
//ajax弹出自定义提示信息
function myAjax(href,cData){
    //alert(cData);
    $.ajax({
        url:href,
        data:cData,
        type:'post',
        success:function(data){
            showMsg(data);
        },
        error:function(){$.moonbox.error('操作失败！');}
    });
}
var showMsg = function(data){
  var msger = data.split(',');
  switch(msger[1]){
    case "ok":
        $.moonbox.ok(msger[0]);
        break; 
    case "warning":
        $.moonbox.warning(msger[0]);
        break;  
    case "error": 
        $.moonbox.error(msger[0]);
        break;
    default: break;
  }
}
function fillhtml(id, href) {
    $('#' + id).html("<img src=\"/JS/MsgBox/preload.gif\" class=\"loading\" />");
    $$.remove('#' + id);
    $.get(href,function(data) { reveal(id, data); })
}
function fillhtml(id, href, noload) {
    if (noload) {
        $('#' + id).html("<img src=\"/JS/MsgBox/preload.gif\" class=\"loading\" />");
    }
    $$.remove('#' + id);
    $.get(href,function(data) { reveal(id, data); })
}
function fillNewHtml(id, href) {
    $('#' + id).html("<img src=\"/JS/MsgBox/preload.gif\" class=\"loading\" />");
    $$.remove('#' + id);
    $.get(href+"?random="+Math.random(),function(data) {reveal(id,data); })
}
var reveal = function(id,data) {
    $('#'+id).html("");
    $('#'+id).append(decodeURI(data));
}
function GetAjax(href,cData) {
    alert(cData);
    $.ajax({
    url: href,
        cache:false,
        data:cData,
        type:'get',
        success:function(data){
            $.moonbox.ok('操作成功！');
        },
        error:function(){$.moonbox.error('操作失败');}
    });
}

var AppendAjax = function(id, innerhtml) {
    $('#' + id).append(innerhtml);
}

//添加评论
var AppendHtmlAjax = function(id, href) {
    //
    //$('#'+id).html("<img src=\"/JS/MsgBox/preload.gif\" class=\"loading\" />");
    $.get(href, function(data) {
        //reveal(id,data); 
        $('#' + id).append(data);
    })
    var controlId=id.replace("ajaxAppend","commentcontent");
    $("#"+controlId).val("");
}